﻿using ServiceStack.Configuration;
using System;

namespace OneLoginPlugin
{
    public class AccountSettings
    {
        public AccountSettings(IResourceManager appSettings)
            : this(appSettings, null)
        {

        }

        public AccountSettings(IResourceManager appSettings, string referrerUrl)
        {
            certificate = appSettings.GetString("saml.certificate");
            idp_sso_target_url = appSettings.GetString("saml.idp.sso.target.url");
            idp_slo_target_url = appSettings.GetString("saml.idp.sso.target.url");

            Recipient = appSettings.GetString("saml.consumer.service.url");

            if (string.IsNullOrEmpty(Recipient))
            {
                throw new ApplicationException("Consumer Service URL must be configured!");
            }
            else
            {
                AssertionConsumerServiceUrl = Recipient.TrimEnd(new char[] { '/' }) + "/auth/saml";

            }

        }

        public string certificate { get; set; }
        public string idp_sso_target_url { get; set; }
        public string idp_slo_target_url { get; set; } 

        public string Recipient { get; set; }

        public string AssertionConsumerServiceUrl { get; set; }
        public string issuer = "SAML Test Connector";
    }
}
